<?php
  class userlogs {
    var $id;
    var $user_id;
    var $date_log;
    var $session_id;
    var $user_agent;
    var $log_out;
    var $on_line;
    var $ip_address;

    function open($id){
        global $db;
        $sql="select * from _user_logs where user_id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->user_id=$user_id;
            $this->date_log=$date_log;
            $this->session_id=$session_id;
            $this->user_agent=$user_agent;
            $this->log_out=$log_out;
            $this->on_line=$on_line;
            $this->ip_address=$ip_address;
        }
    }

    function openAll(){
        $sql="select * from _user_logs order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function login(){
    global $db;
    $sql="insert into _user_logs values (null,'{$this->user_id}',
    sysdate(),'{$this->session_id}','{$this->user_agent}','{$this->ip_address}',null,'1')";
    $db->query($sql);
    return mysql_insert_id();
    }
    function logout(){
        global $db;
        $sql="update _user_logs set 
        log_out=sysdate(),on_line='0' 
        where session_id='{$this->session_id}' and 
        user_id={$this->user_id}";
        $db->query($sql);
    }
    function update(){
        global $db;
        $sql="update _user_logs set user_agent='{$this->user_agent}',
        on_line='{$this->on_line}',ip_address='{$this->ip_address}' 
        where session_id='{$this->session_id}' and 
        user_id={$this->user_id}";
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from _user_logs where id=".$this->id;
        $db->query($sql);
    }

}
?>
